import { getFileList } from "@/api/file/file";
import { defineStore } from "pinia";
const useFileStore = defineStore("file", {
  state: () => ({
    file: [],
    isShow: false,
    uploadFileList: [],
    chunkSize: 1024 * 1024 * 10, //10M
    currentFileIndex: 0,
    FILE_UPLOAD_ID_KEY: "file_upload_id",
    FileStatus: {
      wait: "等待上传",
      getMd5: "校验MD5",
      chip: "正在创建序列",
      uploading: "正在上传",
      success: "上传成功",
      error: "上传错误",
    },
    simultaneousUploads: 3,
    uploadIdInfo: null,
  }),
  actions: {
    async getFileLists(prefix = "") {
      try {
        const res = await getFileList(prefix);
        this.file = res.data;
      } catch (error) {
        console.error("获取文件列表失败", error);
      }
    },
    incrCurrentFileIndex() {
      this.currentFileIndex++;
    },
    updateCurrentFileIndex(index) {
      this.currentFileIndex = index;
    },
    updateUploadFileList(filelist) {
      this.uploadFileList = filelist;
    },
    updateUploadIdInfo(info) {
      this.uploadIdInfo = info;
    },
  },
});

export default useFileStore;
